package com.eyolo.grpcserver.server.rpc;

import com.eyolo.grpcserver.server.service.SCWrapperService;
import lombok.extern.slf4j.Slf4j;
import net.devh.boot.grpc.server.service.GrpcService;
import scwrapper.SCWrapperGrpc;
import scwrapper.Sc;

import javax.annotation.Resource;

@Slf4j
@GrpcService
public class SCWrapperManager extends SCWrapperGrpc.SCWrapperImplBase {

    @Resource
    private SCWrapperService scWrapperService;

    /**
     * <pre>
     * 提交铸销币申请, header需要携带用户id.
     * </pre>
     */
    @Override
    public void applyExchange(Sc.ApplyExchangeReq request, io.grpc.stub.StreamObserver<Sc.NoResp> responseObserver) {

        log.info("接收铸销币请求 ApplyExchangeReq:{}", request);
        scWrapperService.applyExchange(request);
        responseObserver.onNext(Sc.NoResp.newBuilder().build());
        responseObserver.onCompleted();
    }

}
